package com.bwie.House.controller;

import com.bwie.House.config.OSSFileUtil;
import com.bwie.House.service.RenthouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bwie.house.entity.RenthouseEntity;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author wangmo
 * @email wangmo@gmail.com
 * @date 2021-10-13 19:50:25
 */
@RestController
@RequestMapping("house/renthouse")
//@CrossOrigin
public class RenthouseController {
    @Autowired
    private RenthouseService renthouseService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = renthouseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{rentHouseid}")
    public R info(@PathVariable("rentHouseid") Integer rentHouseid){
		RenthouseEntity renthouse = renthouseService.getById(rentHouseid);

        return R.ok().put("renthouse", renthouse);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RenthouseEntity renthouse){
		renthouseService.save(renthouse);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RenthouseEntity renthouse){
		renthouseService.updateById(renthouse);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] rentHouseids){
		renthouseService.removeByIds(Arrays.asList(rentHouseids));

        return R.ok();
    }

    @PostMapping("/upload")
    public String upload(MultipartFile file) throws IOException {
        String s = OSSFileUtil.uploadFile(file);
        return s;
    }

}
